<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>刷题随笔 | Dingzh's Blog</title><meta name="keywords" content="随笔,刷题"><meta name="author" content="Dingzh"><meta name="copyright" content="Dingzh"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="刷题感悟随记"><meta property="og:type" content="article"><meta property="og:title" content="刷题随笔"><meta property="og:url" content="https://dingzh.cc/posts/ee8ba81c.html"><meta property="og:site_name" content="Dingzh&#39;s Blog"><meta property="og:description" content="刷题感悟随记"><meta property="og:locale" content="zh_CN"><meta property="og:image" content="https://alicdn.dingzh.cc/ding-BlogDemo/img/cover/cover110.jpg"><meta property="article:published_time" content="2022-01-02T11:22:36.000Z"><meta property="article:modified_time" content="2025-11-11T15:45:56.425Z"><meta property="article:author" content="Dingzh"><meta property="article:tag" content="随笔"><meta property="article:tag" content="刷题"><meta name="twitter:card" content="summary"><meta name="twitter:image" content="https://alicdn.dingzh.cc/ding-BlogDemo/img/cover/cover110.jpg"><link rel="shortcut icon" href="https://alicdn.dingzh.cc/ding-BlogDemo/img/Favicon.png"><link rel="canonical" href="https://dingzh.cc/posts/ee8ba81c"><link rel="preconnect" href="//cdn.jsdelivr.net"><link rel="preconnect" href="//busuanzi.ibruce.info"><link rel="manifest" href="/manifest.json"><meta name="msapplication-TileColor" content="#f7cb98"><link rel="apple-touch-icon" sizes="180x180" href="https://alicdn.dingzh.cc/ding-BlogDemo/img/siteicon/apple-touch-icon.png"><link rel="icon" type="image/png" sizes="32x32" href="https://alicdn.dingzh.cc/ding-BlogDemo/img/siteicon/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="https://alicdn.dingzh.cc/ding-BlogDemo/img/siteicon/favicon-16x16.png"><link rel="mask-icon" href="https://alicdn.dingzh.cc/ding-BlogDemo/img/siteicon/safari-pinned-tab.svg" color="#5bbad5"><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://npm.elemecdn.com/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://npm.elemecdn.com/node-snackbar/dist/snackbar.min.css" media="print" onload='this.media="all"'><script>const GLOBAL_CONFIG={root:"/",algolia:void 0,localSearch:{path:"search.xml",languages:{hits_empty:"找不到您查询的内容：${query}"}},translate:void 0,noticeOutdate:void 0,highlight:{plugin:"highlighjs",highlightCopy:!0,highlightLang:!0,highlightHeightLimit:250},copy:{success:"复制成功",error:"复制错误",noSupport:"浏览器不支持"},relativeDate:{homepage:!1,post:!1},runtime:"天",date_suffix:{just:"刚刚",min:"分钟前",hour:"小时前",day:"天前",month:"个月前"},copyright:void 0,lightbox:"fancybox",Snackbar:{chs_to_cht:"你已切换为繁体",cht_to_chs:"你已切换为简体",day_to_night:"你已切换为深色模式",night_to_day:"你已切换为浅色模式",bgLight:"#ff6262",bgDark:"#7a3939",position:"top-center"},source:{jQuery:"https://npm.elemecdn.com/jquery@latest/dist/jquery.min.js",justifiedGallery:{js:"https://npm.elemecdn.com/justifiedGallery/dist/js/jquery.justifiedGallery.min.js",css:"https://npm.elemecdn.com/justifiedGallery/dist/css/justifiedGallery.min.css"},fancybox:{js:"https://alicdn.dingzh.cc/ding-BlogDemo/js/other/jquery.fancybox.min.js",css:"https://npm.elemecdn.com/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css"}},isPhotoFigcaption:!1,islazyload:!0,isanchor:!1}</script><script id="config-diff">var GLOBAL_CONFIG_SITE={title:"刷题随笔",isPost:!0,isHome:!1,isHighlightShrink:!1,isToc:!0,postUpdate:"2025-11-11 23:45:56"}</script><noscript><style>#nav{opacity:1}.justified-gallery img{opacity:1}#post-meta time,#recent-posts time{display:inline!important}</style></noscript><script>(e=>{e.saveToLocal={set:function(e,t,o){if(0===o)return;const n=864e5*o,a={value:t,expiry:(new Date).getTime()+n};localStorage.setItem(e,JSON.stringify(a))},get:function(e){const t=localStorage.getItem(e);if(!t)return;const o=JSON.parse(t);if(!((new Date).getTime()>o.expiry))return o.value;localStorage.removeItem(e)}},e.getScript=e=>new Promise((t,o)=>{const n=document.createElement("script");n.src=e,n.async=!0,n.onerror=o,n.onload=n.onreadystatechange=function(){const e=this.readyState;e&&"loaded"!==e&&"complete"!==e||(n.onload=n.onreadystatechange=null,t())},document.head.appendChild(n)}),e.activateDarkMode=function(){document.documentElement.setAttribute("data-theme","dark"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","#0d0d0d")},e.activateLightMode=function(){document.documentElement.setAttribute("data-theme","light"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","#ffffff")};const t=saveToLocal.get("theme"),o=(new Date).getHours();void 0===t?o<=6||o>=18?activateDarkMode():activateLightMode():"light"===t?activateLightMode():activateDarkMode();const n=saveToLocal.get("aside-status");void 0!==n&&("hide"===n?document.documentElement.classList.add("hide-aside"):document.documentElement.classList.remove("hide-aside"));const a=saveToLocal.get("global-font-size");void 0!==a&&document.documentElement.style.setProperty("--global-font-size",a+"px");const c=()=>{GLOBAL_CONFIG_SITE.isHome&&/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)&&document.documentElement.classList.add("apple")};c(),document.addEventListener("pjax:complete",c)})(window)</script><script defer src="https://alicdn.dingzh.cc/ding-BlogDemo/js/custom/randombg.min.js"></script><svg aria-hidden="true" style="position:absolute;overflow:hidden;width:0;height:0"><symbol id="icon-sun" viewBox="0 0 1024 1024"><path d="M960 512l-128 128v192h-192l-128 128-128-128H192v-192l-128-128 128-128V192h192l128-128 128 128h192v192z" fill="#FFD878" p-id="8420"></path><path d="M736 512a224 224 0 1 0-448 0 224 224 0 1 0 448 0z" fill="#FFE4A9" p-id="8421"></path><path d="M512 109.248 626.752 224H800v173.248L914.752 512 800 626.752V800h-173.248L512 914.752 397.248 800H224v-173.248L109.248 512 224 397.248V224h173.248L512 109.248M512 64l-128 128H192v192l-128 128 128 128v192h192l128 128 128-128h192v-192l128-128-128-128V192h-192l-128-128z" fill="#4D5152" p-id="8422"></path><path d="M512 320c105.888 0 192 86.112 192 192s-86.112 192-192 192-192-86.112-192-192 86.112-192 192-192m0-32a224 224 0 1 0 0 448 224 224 0 0 0 0-448z" fill="#4D5152" p-id="8423"></path></symbol><symbol id="icon-moon" viewBox="0 0 1024 1024"><path d="M611.370667 167.082667a445.013333 445.013333 0 0 1-38.4 161.834666 477.824 477.824 0 0 1-244.736 244.394667 445.141333 445.141333 0 0 1-161.109334 38.058667 85.077333 85.077333 0 0 0-65.066666 135.722666A462.08 462.08 0 1 0 747.093333 102.058667a85.077333 85.077333 0 0 0-135.722666 65.024z" fill="#FFB531" p-id="11345"></path><path d="M329.728 274.133333l35.157333-35.157333a21.333333 21.333333 0 1 0-30.165333-30.165333l-35.157333 35.157333-35.114667-35.157333a21.333333 21.333333 0 0 0-30.165333 30.165333l35.114666 35.157333-35.114666 35.157334a21.333333 21.333333 0 1 0 30.165333 30.165333l35.114667-35.157333 35.157333 35.157333a21.333333 21.333333 0 1 0 30.165333-30.165333z" fill="#030835" p-id="11346"></path></symbol></svg><link rel="stylesheet" href="https://alicdn.dingzh.cc/ding-BlogDemo/css/card.min.css" media="defer" onload='this.media="all"'><link rel="stylesheet" href="https://alicdn.dingzh.cc/ding-BlogDemo/clock/clock.min.css"><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://alicdn.dingzh.cc/ding-BlogDemo/css/swiperstyle.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-wowjs/lib/animate.min.css" media="print" onload='this.media="screen"'><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-tag-plugins-plus@latest/lib/assets/font-awesome-animation.min.css" media="defer" onload='this.media="all"'><link rel="stylesheet" href="https://alicdn.dingzh.cc/ding-BlogDemo/css/tag_plugins.min.css" media="defer" onload='this.media="all"'><meta name="generator" content="Hexo 6.0.0"></head><body><a href="javascript:void(0);" onclick="preloader.endLoading()" title="点击跳过动画"><div id="loading-box"><div class="pokeball-back"></div><div class="pokeball-loading"><div class="pokeball" id="pokeball-normal"></div><div class="pokeball" id="pokeball-great"></div><div class="pokeball" id="pokeball-ultra"></div><div class="pokeball" id="pokeball-master"></div><div class="pokeball" id="pokeball-safari"></div></div></div></a><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://alicdn.dingzh.cc/ding-BlogDemo/img/head1.jpg" onerror='onerror=null,src="https://alicdn.dingzh.cc/ding-BlogDemo/img/imgLink_404.gif"' alt="avatar"></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">38</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">49</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div></div></div><hr><div class="menus_items"><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-shouye"></use></svg> <span>首页</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="javascript:void(0);"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-zixun"></use></svg> <span>文章</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/archives/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-danganku"></use></svg> <span>归档</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/tags/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-biaoqian"></use></svg> <span>标签</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/categories/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-wenjianjia"></use></svg> <span>分类</span></a></li></ul></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="javascript:void(0);"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-guochandonghuatuijian"></use></svg> <span>动漫</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/anime/tv/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-anime"></use></svg> <span>季度</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/anime/collect/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-a-vpszhujifuwuqiwangluo"></use></svg> <span>藏馆</span></a></li><li><a class="site-page child faa-parent animated-hover" target="_blank" rel="noopener" href="https://github.com/rplalala/MySubTittle"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-dianying"></use></svg> <span>字幕</span></a></li></ul></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="javascript:void(0);"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-a-switch2"></use></svg> <span>其他</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/gallery/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xiangce"></use></svg> <span>图库</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/artitalk/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-pinglun1"></use></svg> <span>随言</span></a></li></ul></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/messageboard/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-rili"></use></svg> <span>留言板</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="javascript:void(0);"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-youqinglianjie"></use></svg> <span>链接</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/link/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-friendship"></use></svg> <span>友链</span></a></li><li><a class="site-page child faa-parent animated-hover" target="_blank" rel="noopener" href="https://vercel.dingzh.cc"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-a-internethulianwangwangluo"></use></svg> <span>镜像</span></a></li><li><a class="site-page child faa-parent animated-hover" href="https://dingzh.cc"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-a-vpszhujifuwuqiwangluo"></use></svg> <span>主站</span></a></li></ul></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/about/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-wode2"></use></svg> <span>关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image:url(https://alicdn.dingzh.cc/ding-BlogDemo/img/cover/cover110.jpg)"><nav id="nav"><span id="blog_name"><a id="site-name" onclick="btf.scrollToDest(0,500)" data-title="刷题感悟随记">刷题随笔</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search faa-parent animated-hover"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-sousuo4"></use></svg> <span>搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-shouye"></use></svg> <span>首页</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="javascript:void(0);"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-zixun"></use></svg> <span>文章</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/archives/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-danganku"></use></svg> <span>归档</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/tags/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-biaoqian"></use></svg> <span>标签</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/categories/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-wenjianjia"></use></svg> <span>分类</span></a></li></ul></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="javascript:void(0);"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-guochandonghuatuijian"></use></svg> <span>动漫</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/anime/tv/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-anime"></use></svg> <span>季度</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/anime/collect/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-a-vpszhujifuwuqiwangluo"></use></svg> <span>藏馆</span></a></li><li><a class="site-page child faa-parent animated-hover" target="_blank" rel="noopener" href="https://github.com/rplalala/MySubTittle"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-dianying"></use></svg> <span>字幕</span></a></li></ul></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="javascript:void(0);"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-a-switch2"></use></svg> <span>其他</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/gallery/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-xiangce"></use></svg> <span>图库</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/artitalk/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-pinglun1"></use></svg> <span>随言</span></a></li></ul></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/messageboard/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-rili"></use></svg> <span>留言板</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="javascript:void(0);"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-youqinglianjie"></use></svg> <span>链接</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/link/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-friendship"></use></svg> <span>友链</span></a></li><li><a class="site-page child faa-parent animated-hover" target="_blank" rel="noopener" href="https://vercel.dingzh.cc"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-a-internethulianwangwangluo"></use></svg> <span>镜像</span></a></li><li><a class="site-page child faa-parent animated-hover" href="https://dingzh.cc"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-a-vpszhujifuwuqiwangluo"></use></svg> <span>主站</span></a></li></ul></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/about/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-wode2"></use></svg> <span>关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">刷题随笔<a class="post-edit-link" href="https://github.com/rplalala/BlogSource/edit/main/source/_posts/刷题随笔.md" title="编辑" target="_blank"><i class="fas fa-pencil-alt"></i></a></h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-01-02T11:22:36.000Z" title="发表于 2022-01-02 19:22:36">2022-01-02</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2025-11-11T15:45:56.425Z" title="更新于 2025-11-11 23:45:56">2025-11-11</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%88%B7%E9%A2%98%E4%B8%8E%E9%A2%98%E8%A7%A3/">刷题与题解</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.5k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>6分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" data-flag-title="刷题随笔"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="踩坑记录"><a href="#踩坑记录" class="headerlink" title="踩坑记录"></a>踩坑记录</h1><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">1. 3/2.0、1.0*3/2 都可以是1.5。</span><br><span class="line">   但是3/2*1.0不行，因为是先3/2强制取整变成1后再*1.0变为1.0。</span><br><span class="line">   所以要注意先后顺序。</span><br><span class="line">   </span><br><span class="line">2. 做题时，先看看能不能采用即时处理。</span><br><span class="line">   如果想着先全部处理完再输出很可能超时，但如果是一边处理判断一边输出则不容易超时</span><br><span class="line">   https://blog.csdn.net/RP123123123/article/details/122272967</span><br></pre></td></tr></table></figure><h1 id="可以用-int数组-代替-HashMap"><a href="#可以用-int数组-代替-HashMap" class="headerlink" title="可以用 int数组 代替 HashMap"></a>可以用 int数组 代替 HashMap<character ,integer></character></h1><h2 id="常用于对字符串进行操作的算法题中，用来实现滑动窗口"><a href="#常用于对字符串进行操作的算法题中，用来实现滑动窗口" class="headerlink" title="常用于对字符串进行操作的算法题中，用来实现滑动窗口"></a>常用于对字符串进行操作的算法题中，用来实现滑动窗口</h2><p><strong>目的：</strong> 提高效率，也更便于操作value</p><h2 id="为什么可以这样做？？"><a href="#为什么可以这样做？？" class="headerlink" title="为什么可以这样做？？"></a>为什么可以这样做？？</h2><p>因为字符型ascii码最高就到128，所以只要创建一个占据128内存的数组就行，所占空间少。<br>其次字符型可以根据ascii码转成int，此时数组的下标所对应的字符（通过ascii码）就是key，下标对应的值就是value。例如a[65]=5<br>相当于 key=’A’,value=5</p><h1 id="判断一个数是否是整数"><a href="#判断一个数是否是整数" class="headerlink" title="判断一个数是否是整数"></a>判断一个数是否是整数</h1><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 判断s是否是整数</span></span><br><span class="line"><span class="keyword">if</span>(s == (<span class="keyword">int</span>) s)&#123;</span><br><span class="line">    <span class="keyword">return</span> 整数</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><h1 id="判断素数"><a href="#判断素数" class="headerlink" title="判断素数"></a>判断素数</h1><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//判断num是否是素数</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">prime</span><span class="params">(<span class="keyword">int</span> num)</span></span>&#123;</span><br><span class="line">    <span class="comment">// 1不是素数</span></span><br><span class="line">    <span class="keyword">if</span>(num &lt;= <span class="number">1</span>)&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 关键：i &lt;= (int)Math.sqrt(num)</span></span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">2</span>; i &lt;= (<span class="keyword">int</span>)Math.sqrt(num); i++)&#123;</span><br><span class="line">        <span class="keyword">if</span>(num % i == <span class="number">0</span>)&#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><h1 id="反转数字"><a href="#反转数字" class="headerlink" title="反转数字"></a>反转数字</h1><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//反转数字，用来判断是否是回文数</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">reverse</span><span class="params">(<span class="keyword">int</span> num)</span></span>&#123;</span><br><span class="line">    <span class="keyword">int</span> ans = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">while</span>(num &gt; <span class="number">0</span>)&#123;</span><br><span class="line">        ans = ans*<span class="number">10</span> + (num%<span class="number">10</span>);</span><br><span class="line">        num = num/<span class="number">10</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> ans;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><h1 id="浮点数取整"><a href="#浮点数取整" class="headerlink" title="浮点数取整"></a>浮点数取整</h1><ul><li>Math.ceil(double n); //对浮点数向上取整</li><li>Math.floor(double n); //对浮点数向下取整</li><li>Math.round(double n); //对浮点数四舍五入取整，不够准确。例如：-11.5 -&gt; -11</li></ul><h2 id="利用大数类进行准确的四舍五入"><a href="#利用大数类进行准确的四舍五入" class="headerlink" title="利用大数类进行准确的四舍五入"></a>利用大数类进行准确的四舍五入</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">//对10.7进行四舍五入取整</span><br><span class="line">new BigDecimal(&quot;10.7&quot;).setScale(0,BigDecimal.ROUND_HALF_UP).intValue();</span><br></pre></td></tr></table></figure><h1 id="求最大公约数和最小公倍数"><a href="#求最大公约数和最小公倍数" class="headerlink" title="求最大公约数和最小公倍数"></a>求最大公约数和最小公倍数</h1><ul><li>最大公约数：比如说 15和12 的最大公约数 是 3</li><li>最小公倍数：比如说 2 和 5 的最小公倍数 是 10</li><li>最小公倍数 = a*b/a和b的最大公约数</li></ul><h2 id="最大公约数的实现-——-辗转相除法（欧几里得算法）"><a href="#最大公约数的实现-——-辗转相除法（欧几里得算法）" class="headerlink" title="最大公约数的实现 —— 辗转相除法（欧几里得算法）"></a>最大公约数的实现 —— 辗转相除法（欧几里得算法）</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">1. c = a % b;</span><br><span class="line">2. 若 c == 0 ，则 b 是 a和b 的最大公约数</span><br><span class="line">3. 若 c != 0 ，则 令 a = b，b = c，再次执行第一步。</span><br><span class="line"></span><br><span class="line">若要求最小公倍数，则在求出最大公约数后，用 最小公倍数 = a*b/a和b的最大公约数</span><br></pre></td></tr></table></figure><h2 id="最大公约数"><a href="#最大公约数" class="headerlink" title="最大公约数"></a>最大公约数</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">GCD</span><span class="params">(<span class="keyword">int</span> a,<span class="keyword">int</span> b)</span></span>&#123;      <span class="comment">//求最大公约数</span></span><br><span class="line">    <span class="keyword">int</span> t,c;</span><br><span class="line">    <span class="keyword">if</span>(a &lt; b)&#123;</span><br><span class="line">        t = a;</span><br><span class="line">        a = b;</span><br><span class="line">        b = t;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">while</span>(a%b != <span class="number">0</span>)&#123;</span><br><span class="line">        c = a % b;</span><br><span class="line">        a = b;</span><br><span class="line">        b = c;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> b;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><h2 id="最小公倍数"><a href="#最小公倍数" class="headerlink" title="最小公倍数"></a>最小公倍数</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">LCM</span><span class="params">(<span class="keyword">int</span> a,<span class="keyword">int</span> b)</span></span>&#123; <span class="comment">//求最小公倍数</span></span><br><span class="line">    <span class="keyword">return</span> a*b/GCD(a,b);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><h1 id="四舍五入"><a href="#四舍五入" class="headerlink" title="四舍五入"></a>四舍五入</h1><ul><li>Math.ceil(double n); //对浮点数向上取整</li><li>Math.floor(double n); //对浮点数向下取整</li><li>Math.round(double n); //对浮点数四舍五入取整，不够准确。例如：-11.5 -&gt; -11</li></ul><h2 id="利用大数类进行准确的四舍五入-1"><a href="#利用大数类进行准确的四舍五入-1" class="headerlink" title="利用大数类进行准确的四舍五入"></a>利用大数类进行准确的四舍五入</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">//对10.7进行四舍五入取整</span><br><span class="line">new BigDecimal(&quot;10.7&quot;).setScale(0,BigDecimal.ROUND_HALF_UP).intValue();</span><br></pre></td></tr></table></figure><h1 id="去重"><a href="#去重" class="headerlink" title="去重"></a>去重</h1><ol><li>用Set判断是否已经存在，若存在则不进行操作</li></ol><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">distinct</span><span class="params">(<span class="keyword">int</span>[] a)</span></span>&#123;</span><br><span class="line">    Set&lt;Integer&gt; set = <span class="keyword">new</span> HashSet&lt;&gt;();</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> x : a)&#123;</span><br><span class="line">        <span class="keyword">if</span>(set.add(x))&#123;</span><br><span class="line">            System.out.println(x);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><ol><li>用Stream流</li></ol><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">distinct</span><span class="params">(<span class="keyword">int</span>[] a)</span></span>&#123;</span><br><span class="line">    List&lt;Integer&gt; alist = Arrays.stream(a).distinct().collect(Collectors.toList());</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> x : alist)&#123;</span><br><span class="line">        System.out.println(x);    </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><h1 id="快速输入和快速输出-——-BufferedReader和-BufferWriter"><a href="#快速输入和快速输出-——-BufferedReader和-BufferWriter" class="headerlink" title="快速输入和快速输出 —— BufferedReader和 BufferWriter"></a>快速输入和快速输出 —— BufferedReader和 BufferWriter</h1><h2 id="输入-——-BufferedReader"><a href="#输入-——-BufferedReader" class="headerlink" title="输入 —— BufferedReader"></a>输入 —— BufferedReader</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">BufferedReader in = <span class="keyword">new</span> BufferedReader(<span class="keyword">new</span> InputStreamReader(System.in)); 实例化</span><br><span class="line">String/<span class="keyword">char</span>/<span class="keyword">int</span> s1 = in.read();     读入一个字符。可单独读入空格或回车，回车会留下来被下次读取接收（吸收一个\n留下一个\r）</span><br><span class="line">String s2 = in.readLine(); 读入一行，可读入空格。遇到回车结束，且回车会被舍弃，不会再被下次读取</span><br><span class="line">String[] ss = in.readLine().split(<span class="string">&quot; &quot;</span>); 将读入的一行字符串以空格分为字符串数组</span><br><span class="line">……</span><br><span class="line">in.close();  关闭流</span><br></pre></td></tr></table></figure><p><strong>需要注意的是：</strong></p><ul><li>在windows中按一下回车键，一共有两个字符 “\n\r”，而read()只能读取一个字符所以如要用read来达到吸收回车的目的，需要用两个read(); 如果用readLine()的话会将”\n\r”全部吸收 ， 所以只需要一个readLine()来吸收回车。</li><li>由于是字符型，用read()读取整型时，读取0会显示其as码48，读取9以上的数就会出问题了。所以我们应该用readLine()来接收，再利用Integer.parseInt()转化为整型</li></ul><h2 id="输出-——-BufferWriter"><a href="#输出-——-BufferWriter" class="headerlink" title="输出 —— BufferWriter"></a>输出 —— BufferWriter</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">BufferedWriter out = <span class="keyword">new</span> BufferedWriter(<span class="keyword">new</span> OutputStreamWriter(System.out)); 实例化 </span><br><span class="line">out.write(x);</span><br><span class="line">out.write(<span class="string">&quot; &quot;</span>);</span><br><span class="line">out.write(<span class="string">&quot;\n&quot;</span>);</span><br><span class="line">out.write(x+<span class="string">&quot;\n&quot;</span>);</span><br><span class="line">……</span><br><span class="line">out.flush();  在程序最后刷新一次即可，确保缓冲区的数据全部被输出</span><br><span class="line">out.close();  先刷新后关闭</span><br><span class="line"></span><br></pre></td></tr></table></figure><p><strong>需要注意的是：</strong></p><ul><li>write()不能直接输出int类型。因为BufferWriter是字符型流，直接用write(int a) 会输出其对应的ASCii码的字符 ,比如输出 65 会显示 A。可以通过write(String.valueOf(a)) 或 write(a+””)实现</li></ul><h2 id="记得在类声明后进行异常处理，throws-IOException"><a href="#记得在类声明后进行异常处理，throws-IOException" class="headerlink" title="记得在类声明后进行异常处理，throws IOException"></a>记得在类声明后进行异常处理，throws IOException</h2><h1 id="利用-String-format-格式化数据"><a href="#利用-String-format-格式化数据" class="headerlink" title="利用 String.format() 格式化数据"></a>利用 String.format() 格式化数据</h1><p>原理类似于System.out.printf();<br></p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">String s1 = String.format(<span class="string">&quot;%.2f\n&quot;</span>,<span class="number">10.34567</span>);</span><br><span class="line">String s2 = String.format(<span class="string">&quot;你的名字是：%s\n&quot;</span>,<span class="string">&quot;丁梓航&quot;</span>);</span><br></pre></td></tr></table></figure><p></p><h1 id="求集合的交集、差集、并集"><a href="#求集合的交集、差集、并集" class="headerlink" title="求集合的交集、差集、并集"></a>求集合的交集、差集、并集</h1><h2 id="交集-——-retainAll"><a href="#交集-——-retainAll" class="headerlink" title="交集 —— retainAll()"></a>交集 —— retainAll()</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">se1.retainAll(set2)    <span class="comment">//求set1和set2的交集，最终结果留在set1</span></span><br><span class="line">        </span><br><span class="line">set1 = &#123;<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">7</span>&#125;，set2 = &#123;<span class="number">1</span>,<span class="number">3</span>,<span class="number">8</span>,<span class="number">9</span>&#125;</span><br><span class="line">=&gt; set1 = &#123;<span class="number">1</span>,<span class="number">3</span>&#125;</span><br></pre></td></tr></table></figure><h2 id="差集-——-removeAll"><a href="#差集-——-removeAll" class="headerlink" title="差集 —— removeAll()"></a>差集 —— removeAll()</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">se1.removeAll(set2)    <span class="comment">//求set1和set2的差集，最终结果留在set1</span></span><br><span class="line">        </span><br><span class="line">set1 = &#123;<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">7</span>&#125;，set2 = &#123;<span class="number">1</span>,<span class="number">3</span>,<span class="number">8</span>,<span class="number">9</span>&#125;</span><br><span class="line">=&gt; set1 = &#123;<span class="number">2</span>,<span class="number">7</span>&#125;</span><br></pre></td></tr></table></figure><h2 id="并集-——-addAll"><a href="#并集-——-addAll" class="headerlink" title="并集 —— addAll()"></a>并集 —— addAll()</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">se1.addAll(set2)    <span class="comment">//求set1和set2的并集，最终结果留在set1</span></span><br><span class="line">        </span><br><span class="line">set1 = &#123;<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">7</span>&#125;，set2 = &#123;<span class="number">1</span>,<span class="number">3</span>,<span class="number">8</span>,<span class="number">9</span>&#125;</span><br><span class="line">=&gt; set1 = &#123;<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">7</span>,<span class="number">8</span>,<span class="number">9</span>&#125;</span><br></pre></td></tr></table></figure></article><div class="post-copyright"><div class="post-copyright__title"><span class="post-copyright-info"><h>刷题随笔</h></span></div><div class="post-copyright__type"><span class="post-copyright-info"><a href="https://dingzh.cc/posts/ee8ba81c.html">https://dingzh.cc/posts/ee8ba81c.html</a></span></div><div class="post-copyright-m"><div class="post-copyright-m-info"><div class="post-copyright-a"><h>作者</h><div class="post-copyright-cc-info"><h>Dingzh</h></div></div><div class="post-copyright-c"><h>发布于</h><div class="post-copyright-cc-info"><h>2022-01-02</h></div></div><div class="post-copyright-u"><h>更新于</h><div class="post-copyright-cc-info"><h>2025-11-11</h></div></div><div class="post-copyright-c"><h>许可协议</h><div class="post-copyright-cc-info"><a class="icon" rel="noopener" target="_blank" title="Creative Commons" href="https://creativecommons.org/"><i class="fab fa-creative-commons"></i></a><a rel="noopener" target="_blank" title="CC BY-NC-SA 4.0" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a></div></div></div></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E9%9A%8F%E7%AC%94/">随笔</a><a class="post-meta__tags" href="/tags/%E5%88%B7%E9%A2%98/">刷题</a></div><div class="post_share"><div class="social-share" data-image="https://alicdn.dingzh.cc/ding-BlogDemo/img/cover/cover110.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://npm.elemecdn.com/social-share.js/dist/css/share.min.css" media="print" onload='this.media="all"'><script src="https://npm.elemecdn.com/social-share.js/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button button--animated"><i class="fas fa-qrcode"></i> 打赏<div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://alicdn.dingzh.cc/ding-BlogDemo/img/wechat.jpg" target="_blank"><img class="post-qr-code-img" src="https://alicdn.dingzh.cc/ding-BlogDemo/img/wechat.jpg" alt="微信"></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="https://alicdn.dingzh.cc/ding-BlogDemo/img/alipay.jpg" target="_blank"><img class="post-qr-code-img" src="https://alicdn.dingzh.cc/ding-BlogDemo/img/alipay.jpg" alt="支付宝"></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/posts/f96a58f3.html"><img class="prev-cover" src="https://alicdn.dingzh.cc/ding-BlogDemo/img/cover/cover398.jpg" onerror='onerror=null,src="https://alicdn.dingzh.cc/ding-BlogDemo/img/404_img.jpg"' alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Java基础随笔</div></div></a></div><div class="next-post pull-right"><a href="/posts/f77f8e26.html"><img class="next-cover" src="https://alicdn.dingzh.cc/ding-BlogDemo/img/cover/cover259.jpg" onerror='onerror=null,src="https://alicdn.dingzh.cc/ding-BlogDemo/img/404_img.jpg"' alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Hexo+GitHub 实现域名配置（别被旧文章坑了）</div></div></a></div></nav><hr><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i> <span>评论</span></div></div><div class="comment-wrap"><div><div id="twikoo-wrap"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://alicdn.dingzh.cc/ding-BlogDemo/img/head1.jpg" onerror='this.onerror=null,this.src="https://alicdn.dingzh.cc/ding-BlogDemo/img/imgLink_404.gif"' alt="avatar"></div><div class="author-info__name">Dingzh</div><div class="author-info__description">为之则易，不为则难</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">38</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">49</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div></div><a class="button--animated" id="card-info-btn" href="javascript:void(0)" onclick="addFav()"><i class="fas fa-star"></i><span>收藏本站</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/rplalala" target="_blank" title="Github"><i class="fab iconfont icon-github"></i></a><a class="social-icon" href="https://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&amp;email=dingzihang00@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="https://gitee.com/rplalala" target="_blank" title="Gitee"><i class="fab iconfont icon-gitee-fill-round"></i></a><a class="social-icon" href="https://blog.csdn.net/RP123123123?spm=1000.2115.3001.5343" target="_blank" title="CSDN"><i class="fab iconfont icon-csdn1-copy"></i></a><a class="social-icon" href="https://leetcode-cn.com/u/dingzihang00/" target="_blank" title="LeetCode"><i class="fab iconfont icon-leetcode"></i></a><a class="social-icon" href="https://space.bilibili.com/6964209" target="_blank" title="Bilibili"><i class="fab iconfont icon-bilibili-fill"></i></a><a class="social-icon" href="https://i.y.qq.com/n2/m/share/details/taoge.html?id=3885764921" target="_blank" title="QQ音乐"><i class="fab iconfont icon-QQyinle"></i></a></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%B8%A9%E5%9D%91%E8%AE%B0%E5%BD%95"><span class="toc-number">1.</span> <span class="toc-text">踩坑记录</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%8F%AF%E4%BB%A5%E7%94%A8-int%E6%95%B0%E7%BB%84-%E4%BB%A3%E6%9B%BF-HashMap"><span class="toc-number">2.</span> <span class="toc-text">可以用 int数组 代替 HashMap</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B8%B8%E7%94%A8%E4%BA%8E%E5%AF%B9%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BF%9B%E8%A1%8C%E6%93%8D%E4%BD%9C%E7%9A%84%E7%AE%97%E6%B3%95%E9%A2%98%E4%B8%AD%EF%BC%8C%E7%94%A8%E6%9D%A5%E5%AE%9E%E7%8E%B0%E6%BB%91%E5%8A%A8%E7%AA%97%E5%8F%A3"><span class="toc-number">2.1.</span> <span class="toc-text">常用于对字符串进行操作的算法题中，用来实现滑动窗口</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%BA%E4%BB%80%E4%B9%88%E5%8F%AF%E4%BB%A5%E8%BF%99%E6%A0%B7%E5%81%9A%EF%BC%9F%EF%BC%9F"><span class="toc-number">2.2.</span> <span class="toc-text">为什么可以这样做？？</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%88%A4%E6%96%AD%E4%B8%80%E4%B8%AA%E6%95%B0%E6%98%AF%E5%90%A6%E6%98%AF%E6%95%B4%E6%95%B0"><span class="toc-number">3.</span> <span class="toc-text">判断一个数是否是整数</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%88%A4%E6%96%AD%E7%B4%A0%E6%95%B0"><span class="toc-number">4.</span> <span class="toc-text">判断素数</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%8F%8D%E8%BD%AC%E6%95%B0%E5%AD%97"><span class="toc-number">5.</span> <span class="toc-text">反转数字</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%B5%AE%E7%82%B9%E6%95%B0%E5%8F%96%E6%95%B4"><span class="toc-number">6.</span> <span class="toc-text">浮点数取整</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%A9%E7%94%A8%E5%A4%A7%E6%95%B0%E7%B1%BB%E8%BF%9B%E8%A1%8C%E5%87%86%E7%A1%AE%E7%9A%84%E5%9B%9B%E8%88%8D%E4%BA%94%E5%85%A5"><span class="toc-number">6.1.</span> <span class="toc-text">利用大数类进行准确的四舍五入</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%B1%82%E6%9C%80%E5%A4%A7%E5%85%AC%E7%BA%A6%E6%95%B0%E5%92%8C%E6%9C%80%E5%B0%8F%E5%85%AC%E5%80%8D%E6%95%B0"><span class="toc-number">7.</span> <span class="toc-text">求最大公约数和最小公倍数</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9C%80%E5%A4%A7%E5%85%AC%E7%BA%A6%E6%95%B0%E7%9A%84%E5%AE%9E%E7%8E%B0-%E2%80%94%E2%80%94-%E8%BE%97%E8%BD%AC%E7%9B%B8%E9%99%A4%E6%B3%95%EF%BC%88%E6%AC%A7%E5%87%A0%E9%87%8C%E5%BE%97%E7%AE%97%E6%B3%95%EF%BC%89"><span class="toc-number">7.1.</span> <span class="toc-text">最大公约数的实现 —— 辗转相除法（欧几里得算法）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9C%80%E5%A4%A7%E5%85%AC%E7%BA%A6%E6%95%B0"><span class="toc-number">7.2.</span> <span class="toc-text">最大公约数</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9C%80%E5%B0%8F%E5%85%AC%E5%80%8D%E6%95%B0"><span class="toc-number">7.3.</span> <span class="toc-text">最小公倍数</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%9B%9B%E8%88%8D%E4%BA%94%E5%85%A5"><span class="toc-number">8.</span> <span class="toc-text">四舍五入</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%A9%E7%94%A8%E5%A4%A7%E6%95%B0%E7%B1%BB%E8%BF%9B%E8%A1%8C%E5%87%86%E7%A1%AE%E7%9A%84%E5%9B%9B%E8%88%8D%E4%BA%94%E5%85%A5-1"><span class="toc-number">8.1.</span> <span class="toc-text">利用大数类进行准确的四舍五入</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%8E%BB%E9%87%8D"><span class="toc-number">9.</span> <span class="toc-text">去重</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%BF%AB%E9%80%9F%E8%BE%93%E5%85%A5%E5%92%8C%E5%BF%AB%E9%80%9F%E8%BE%93%E5%87%BA-%E2%80%94%E2%80%94-BufferedReader%E5%92%8C-BufferWriter"><span class="toc-number">10.</span> <span class="toc-text">快速输入和快速输出 —— BufferedReader和 BufferWriter</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%BE%93%E5%85%A5-%E2%80%94%E2%80%94-BufferedReader"><span class="toc-number">10.1.</span> <span class="toc-text">输入 —— BufferedReader</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%BE%93%E5%87%BA-%E2%80%94%E2%80%94-BufferWriter"><span class="toc-number">10.2.</span> <span class="toc-text">输出 —— BufferWriter</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%AE%B0%E5%BE%97%E5%9C%A8%E7%B1%BB%E5%A3%B0%E6%98%8E%E5%90%8E%E8%BF%9B%E8%A1%8C%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86%EF%BC%8Cthrows-IOException"><span class="toc-number">10.3.</span> <span class="toc-text">记得在类声明后进行异常处理，throws IOException</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%88%A9%E7%94%A8-String-format-%E6%A0%BC%E5%BC%8F%E5%8C%96%E6%95%B0%E6%8D%AE"><span class="toc-number">11.</span> <span class="toc-text">利用 String.format() 格式化数据</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%B1%82%E9%9B%86%E5%90%88%E7%9A%84%E4%BA%A4%E9%9B%86%E3%80%81%E5%B7%AE%E9%9B%86%E3%80%81%E5%B9%B6%E9%9B%86"><span class="toc-number">12.</span> <span class="toc-text">求集合的交集、差集、并集</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%A4%E9%9B%86-%E2%80%94%E2%80%94-retainAll"><span class="toc-number">12.1.</span> <span class="toc-text">交集 —— retainAll()</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B7%AE%E9%9B%86-%E2%80%94%E2%80%94-removeAll"><span class="toc-number">12.2.</span> <span class="toc-text">差集 —— removeAll()</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B9%B6%E9%9B%86-%E2%80%94%E2%80%94-addAll"><span class="toc-number">12.3.</span> <span class="toc-text">并集 —— addAll()</span></a></li></ol></li></ol></div></div><div class="card-widget card-recommend-post"><div class="item-headline"><i class="fas fa-thumbs-up"></i><span>相关推荐</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/posts/f96a58f3.html" title="Java基础随笔"><img src="https://alicdn.dingzh.cc/ding-BlogDemo/img/cover/cover398.jpg" alt="Java基础随笔"></a><div class="content"><a class="title" href="/posts/f96a58f3.html" title="Java基础随笔">Java基础随笔</a><time datetime="2022-01-02" title="发表于 2022-01-02">2022-01-02</time></div></div></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/posts/b6ddf346.html" title="leetcode hot 100 刷题笔记"><img src="https://alicdn.dingzh.cc/ding-BlogDemo/img/cover/cover258.jpg" onerror='this.onerror=null,this.src="https://alicdn.dingzh.cc/ding-BlogDemo/img/404_img.jpg"' alt="leetcode hot 100 刷题笔记"></a><div class="content"><a class="title" href="/posts/b6ddf346.html" title="leetcode hot 100 刷题笔记">leetcode hot 100 刷题笔记</a><time datetime="2025-11-17T10:40:06.000Z" title="发表于 2025-11-17 18:40:06">2025-11-17</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/5b98c3b1.html" title="纯JWT TOKEN 和Redis + JWT TOKEN的区别和应用场景"><img src="https://alicdn.dingzh.cc/ding-BlogDemo/img/cover/cover122.jpg" onerror='this.onerror=null,this.src="https://alicdn.dingzh.cc/ding-BlogDemo/img/404_img.jpg"' alt="纯JWT TOKEN 和Redis + JWT TOKEN的区别和应用场景"></a><div class="content"><a class="title" href="/posts/5b98c3b1.html" title="纯JWT TOKEN 和Redis + JWT TOKEN的区别和应用场景">纯JWT TOKEN 和Redis + JWT TOKEN的区别和应用场景</a><time datetime="2025-11-16T16:24:56.000Z" title="发表于 2025-11-17 00:24:56">2025-11-17</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/14f08eda.html" title="RAG / MCP / Prompt 和一些常用的 Agent 框架"><img src="https://alicdn.dingzh.cc/ding-BlogDemo/img/cover/cover155.jpg" onerror='this.onerror=null,this.src="https://alicdn.dingzh.cc/ding-BlogDemo/img/404_img.jpg"' alt="RAG / MCP / Prompt 和一些常用的 Agent 框架"></a><div class="content"><a class="title" href="/posts/14f08eda.html" title="RAG / MCP / Prompt 和一些常用的 Agent 框架">RAG / MCP / Prompt 和一些常用的 Agent 框架</a><time datetime="2025-11-11T12:46:47.000Z" title="发表于 2025-11-11 20:46:47">2025-11-11</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/7a10715.html" title="什么是 MCP，什么是 MCP Server"><img src="https://alicdn.dingzh.cc/ding-BlogDemo/img/cover/cover16.jpg" onerror='this.onerror=null,this.src="https://alicdn.dingzh.cc/ding-BlogDemo/img/404_img.jpg"' alt="什么是 MCP，什么是 MCP Server"></a><div class="content"><a class="title" href="/posts/7a10715.html" title="什么是 MCP，什么是 MCP Server">什么是 MCP，什么是 MCP Server</a><time datetime="2025-11-11T08:05:27.000Z" title="发表于 2025-11-11 16:05:27">2025-11-11</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/1383d4dc.html" title="阿里云CDN 配置国内外双源站策略，加快国内外访问"><img src="https://alicdn.dingzh.cc/ding-BlogDemo/img/cover/cover39.jpg" onerror='this.onerror=null,this.src="https://alicdn.dingzh.cc/ding-BlogDemo/img/404_img.jpg"' alt="阿里云CDN 配置国内外双源站策略，加快国内外访问"></a><div class="content"><a class="title" href="/posts/1383d4dc.html" title="阿里云CDN 配置国内外双源站策略，加快国内外访问">阿里云CDN 配置国内外双源站策略，加快国内外访问</a><time datetime="2025-11-09T17:28:32.000Z" title="发表于 2025-11-10 01:28:32">2025-11-10</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright"><span>&copy;2021 - 2025</span><svg style="width:1.5em;height:1.5em" aria-hidden="true"><use xlink:href="#icon-diqiu"></use></svg><span>Dingzh</span></div><div class="footer_custom_text"><span id="timeShow"></span></div><p id="ghbdages"><a class="github-badge" target="_blank" href="https://github.com/rplalala/rplalala.github.io" style="margin-inline:5px"><img src="https://img.shields.io/badge/Source-Github-d021d6?style=flat&amp;logo=GitHub" title="本站项目由Github托管"></a><a class="github-badge" target="_blank" href="https://gitee.com/rplalala/rplalala" style="margin-inline:5px"><img src="https://img.shields.io/badge/Mirror-Gitee-0cedbe?style=flat&amp;logo=Gitee" title="本站国内镜像由Gitee托管"></a><a class="github-badge" target="_blank" href="https://vercel.com/" style="margin-inline:5px"><img src="https://img.shields.io/badge/Hosted-Vercel-brightgreen?style=flat&amp;logo=Vercel" title="本站采用双线部署，默认线路托管于Vercel"></a><a class="github-badge" target="_blank" href="https://www.aliyun.com/" style="margin-inline:5px"><img src="https://img.shields.io/badge/CDN-Aliyun-orange?style=flat&amp;logo=AlibabaCloud" title="本站使用阿里云提供CDN加速"></a><a class="github-badge" target="_blank" href="https://beian.miit.gov.cn/" style="margin-inline:5px"><img src="https://img.shields.io/badge/%E9%97%BDICP%E5%A4%87-2022001031%E5%8F%B7-e1d492?style=flat&amp;logo=" title="本站已在工信部备案，备案号闽ICP备-2022001031号"></a><a class="github-badge" target="_blank" href="https://icp.gov.moe/?keyword=20221220" style="margin-inline:5px"><img src="https://img.shields.io/badge/%E8%90%8CICP%E5%A4%87-20221220%E5%8F%B7-fe1384?style-flat&amp;logo=" title="本站已加入萌ICP备，萌号萌ICP备-20221220号"></a><a class="github-badge" target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/" style="margin-inline:5px"><img src="https://img.shields.io/badge/Copyright-BY--NC--SA%204.0-d42328?style=flat&amp;logo=Claris" title="本站采用知识共享署名-非商业性使用-相同方式共享4.0国际许可协议进行许可"></a><a class="github-badge" target="_blank" href="https://butterfly.js.org/" style="margin-inline:5px"><img src="https://img.shields.io/badge/Theme-Butterfly-6513df?style=flat&amp;logo=bitdefender" title="主题版本为Butterfly_v3.8.4"></a><a class="github-badge" target="_blank" href="https://hexo.io/" style="margin-inline:5px"><img src="https://img.shields.io/badge/Frame-Hexo-blue?style=flat&amp;logo=hexo" title="博客框架为Hexo_v6.0.0"></a></p></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="font-plus" type="button" title="放大字体"><i class="fas fa-plus"></i></button><button id="font-minus" type="button" title="缩小字体"><i class="fas fa-minus"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><a class="icon-V hidden" onclick="switchNightMode()" title="浅色和深色模式转换"><svg width="25" height="25" viewBox="0 0 1024 1024"><use id="modeicon" xlink:href="#icon-moon"></use></svg></a><button id="change-bg-btn" type="button" title="更换背景" onclick="(function(b){var i=b.querySelector('i');if(i)i.classList.add('fa-spin');b.disabled=true;Promise.resolve(window.changeBackground &amp;&amp; changeBackground()).catch(function(e){try{console.error(e)}catch(e){}}).then(function(){if(i)i.classList.remove('fa-spin');b.disabled=false;});})(this)"><i class="fas fa-image"></i></button><button id="cycle-bg-mode-btn" type="button" title="背景模式" data-title-base="背景模式" data-random-label="随机背景" data-white-label="纯白背景" data-black-label="纯黑背景" onclick="window.cycleBackgroundMode &amp;&amp; cycleBackgroundMode(this)"><i class="fas fa-palette"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button><button id="to_comment" type="button" title="直达评论" onclick="FixedCommentBtn()"><i class="fas fa-comments"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"></div></div></div><hr><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="https://npm.elemecdn.com/jquery@latest/dist/jquery.min.js"></script><script src="https://alicdn.dingzh.cc/ding-BlogDemo/js/utils.min.js"></script><script src="https://alicdn.dingzh.cc/ding-BlogDemo/js/main.min.js"></script><script defer src="https://npm.elemecdn.com/instant.page/instantpage.js" type="module"></script><script src="https://npm.elemecdn.com/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script defer src="https://npm.elemecdn.com/node-snackbar/dist/snackbar.min.js"></script><script>function panguFn(){"object"==typeof pangu?pangu.autoSpacingPage():getScript("https://alicdn.dingzh.cc/ding-BlogDemo/js/other/pangu.min.js").then(()=>{pangu.autoSpacingPage()})}function panguInit(){panguFn()}document.addEventListener("DOMContentLoaded",panguInit)</script><script defer src="https://alicdn.dingzh.cc/ding-BlogDemo/js/search/local-search.min.js"></script><script async>var preloader={endLoading:()=>{document.body.style.overflow="auto",document.getElementById("loading-box").classList.add("loaded")},initLoading:()=>{document.body.style.overflow="",document.getElementById("loading-box").classList.remove("loaded")}};window.addEventListener("load",()=>{preloader.endLoading()}),setTimeout((function(){preloader.endLoading()}),2500)</script><div class="js-pjax"><script>(()=>{const t=document.getElementById("twikoo-count"),o=()=>{twikoo.init(Object.assign({el:"#twikoo-wrap",envId:"https://twikoo.dingzh.cc/",region:""},null))},n=()=>{twikoo.getCommentsCount({envId:"https://twikoo.dingzh.cc/",region:"",urls:[window.location.pathname],includeReply:!1}).then((function(o){t.innerText=o[0].count})).catch((function(t){console.error(t)}))},e=(e=!1)=>{"object"==typeof twikoo?(o(),e&&t&&setTimeout(n,0)):getScript("https://alicdn.dingzh.cc/ding-BlogDemo/js/other/twikoo.all.min.js").then(()=>{o(),e&&t&&setTimeout(n,0)})};btf.loadComment(document.getElementById("twikoo-wrap"),e)})()</script></div><script>window.addEventListener("load",()=>{const e=e=>{let t="";if(e.length)for(let n=0;n<e.length;n++){t+="<div class='aside-list-item'>";{const a="data-lazy-src";t+=`<a href='${e[n].url}' class='thumbnail'><img ${a}='${e[n].avatar}' alt='${e[n].nick}'></a>`}t+=`<div class='content'>\n        <a class='comment' href='${e[n].url}'>${e[n].content}</a>\n        <div class='name'><span>${e[n].nick} / </span><time datetime="${e[n].date}">${btf.diffDate(e[n].date,!0)}</time></div>\n        </div></div>`}else t+="没有评论";let n=document.querySelector("#card-newest-comments .aside-list");n.innerHTML=t,window.lazyLoadInstance&&window.lazyLoadInstance.update(),window.pjax&&window.pjax.refresh(n)},t=()=>{if(document.querySelector("#card-newest-comments .aside-list")){const t=saveToLocal.get("twikoo-newest-comments");t?e(JSON.parse(t)):(()=>{const t=()=>{twikoo.getRecentComments({envId:"https://twikoo.dingzh.cc/",region:"",pageSize:6,includeReply:!0}).then((function(t){const n=t.map(e=>{return{content:(t=e.comment,""===t||(t=(t=(t=(t=t.replace(/<img.*?src="(.*?)"?[^\>]+>/gi,"[图片]")).replace(/<a[^>]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>/gi,"[链接]")).replace(/<pre><code>.*?<\/pre>/gi,"[代码]")).replace(/<[^>]+>/g,"")).length>150&&(t=t.substring(0,150)+"..."),t),avatar:e.avatar,nick:e.nick,url:e.url+"#"+e.id,date:new Date(e.created).toISOString()};var t});saveToLocal.set("twikoo-newest-comments",JSON.stringify(n),10/1440),e(n)})).catch((function(e){document.querySelector("#card-newest-comments .aside-list").innerHTML="无法获取评论，请确认相关配置是否正确"}))};"object"==typeof twikoo?t():getScript("https://alicdn.dingzh.cc/ding-BlogDemo/js/other/twikoo.all.min.js").then(t)})()}};t(),document.addEventListener("pjax:complete",t)})</script><script async src="https://alicdn.dingzh.cc/ding-BlogDemo/js/custom/myJS.min.js"></script><script async src="https://at.alicdn.com/t/font_3113985_v9z1ah1pbeo.js"></script><script async src="https://at.alicdn.com/t/font_2032782_ev6ytrh30f.js"></script><script defer src="https://alicdn.dingzh.cc/ding-BlogDemo/js/custom/baidu_sub.min.js"></script><script data-pjax defer src="https://alicdn.dingzh.cc/ding-BlogDemo/js/custom/fixed_card_widget.min.js"></script><script data-pjax defer src="https://alicdn.dingzh.cc/ding-BlogDemo/js/custom/fixedComment_twikoo.min.js"></script><script src="https://alicdn.dingzh.cc/ding-BlogDemo/js/custom/sun_moon.min.js" async></script><script src="https://npm.elemecdn.com/butterfly-extsrc@1/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful=!0,POWERMODE.shake=!1,POWERMODE.mobile=!1,document.body.addEventListener("input",POWERMODE)</script><script id="click-heart" src="https://npm.elemecdn.com/butterfly-extsrc@1/dist/click-heart.min.js" async mobile="false"></script><script src="https://npm.elemecdn.com/pjax/pjax.min.js"></script><script>let pjaxSelectors=["title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show","#fixedcard-dashboard",".js-pjax"];var pjax=new Pjax({elements:'a:not([target="_blank"])',selectors:pjaxSelectors,cacheBust:!1,analytics:!1,scrollRestoration:!1});document.addEventListener("pjax:send",(function(){if(window.removeEventListener("scroll",window.tocScrollFn),window.removeEventListener("scroll",scrollCollect),"object"==typeof preloader&&preloader.initLoading(),window.aplayers)for(let e=0;e<window.aplayers.length;e++)window.aplayers[e].options.fixed||window.aplayers[e].destroy();"object"==typeof typed&&typed.destroy();const e=document.body.classList;e.contains("read-mode")&&e.remove("read-mode")})),document.addEventListener("pjax:complete",(function(){window.refreshFn(),document.querySelectorAll("script[data-pjax]").forEach(e=>{const t=document.createElement("script"),o=e.text||e.textContent||e.innerHTML||"";Array.from(e.attributes).forEach(e=>t.setAttribute(e.name,e.value)),t.appendChild(document.createTextNode(o)),e.parentNode.replaceChild(t,e)}),GLOBAL_CONFIG.islazyload&&window.lazyLoadInstance.update(),"function"==typeof chatBtnFn&&chatBtnFn(),"function"==typeof panguInit&&panguInit(),"function"==typeof gtag&&gtag("config","",{page_path:window.location.pathname}),"object"==typeof _hmt&&_hmt.push(["_trackPageview",window.location.pathname]),"object"==typeof Prism&&Prism.highlightAll(),"object"==typeof preloader&&preloader.endLoading()})),document.addEventListener("pjax:error",e=>{404===e.request.status&&pjax.loadUrl("/404.html")})</script><script async data-pjax src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="fixedcard-dashboard"><button class="fixedcard-activebtn" type="button" title="用户信息" onclick="FixedCardWidget(&quot;class&quot;,&quot;card-info&quot;,&quot;0&quot;)"><i class="fas fa-address-book"></i></button><button class="fixedcard-activebtn" type="button" title="电子钟" onclick="FixedCardWidget(&quot;class&quot;,&quot;card-clock&quot;,&quot;0&quot;)"><i class="fas fa-cloud-sun"></i></button><button class="fixedcard-activebtn" type="button" title="最新文章" onclick="FixedCardWidget(&quot;class&quot;,&quot;card-recent-post&quot;,&quot;0&quot;)"><i class="fas fa-history"></i></button><button class="fixedcard-activebtn" type="button" title="相关推荐" onclick="FixedCardWidget(&quot;class&quot;,&quot;card-recommend-post&quot;,&quot;0&quot;)"><i class="fas fa-thumbs-up"></i></button><div class="fixedcard-user-avatar fixedcard-activebtn" onclick="RemoveFixedCardWidget()"><img class="fixedcard-user-avatar-img" src="https://alicdn.dingzh.cc/ding-BlogDemo/img/head1.jpg" title="Dingzh"></div></div><div class="app-refresh" id="app-refresh" style="position:fixed;top:-2.2rem;left:0;right:0;z-index:99999;padding:0 1rem;font-size:15px;height:2.2rem;transition:all .3s ease"><div class="app-refresh-wrap" style="display:flex;color:#fff;height:100%;align-items:center;justify-content:center"><label>🌈本站有新文章啦💌</label><a href="javascript:void(0)" onclick='top.location.href="/"'><span style="color:#fff;text-decoration:underline;cursor:pointer">🔎查看🤗</span></a></div></div><script>function showNotification(){if(GLOBAL_CONFIG.Snackbar){var t="light"===document.documentElement.getAttribute("data-theme")?GLOBAL_CONFIG.Snackbar.bgLight:GLOBAL_CONFIG.Snackbar.bgDark,e=GLOBAL_CONFIG.Snackbar.position;Snackbar.show({text:"🌈本站有新文章啦💌",backgroundColor:t,duration:5e5,pos:e,actionText:"🔎查看🤗",actionTextColor:"#fff",onActionClick:function(t){top.location.href="/"}})}else{var o=`top: 0; background: ${"light"===document.documentElement.getAttribute("data-theme")?"#49b1f5":"#1f1f1f"};`;document.getElementById("app-refresh").style.cssText=o}}"serviceWorker"in navigator&&(navigator.serviceWorker.controller&&navigator.serviceWorker.addEventListener("controllerchange",(function(){showNotification()})),window.addEventListener("load",(function(){navigator.serviceWorker.register("/sw.js")})))</script></div><script data-pjax>function card_artitalk_injector_config(){var a=document.getElementsByClassName("sticky_layout")[0];console.log("已挂载card_artitalk"),a.insertAdjacentHTML("afterbegin",'<div class="card-widget card-shuo"><div class="card-content" style="height:auto;min-height:280px;"><div class="item-headline"><i class="fas fa-comments"></i><span><a href="/artitalk/" title="artitalk page link">随言</a></span><a id="cardVisual" style="cursor:pointer;float:right" onclick="cardVisual()">编辑</a></div><div id="artitalk_main" style="width:100%;height:100%;padding:1px"></div></div></div>'),(()=>{const a=()=>{new Artitalk(Object.assign({appId:"5EG25co78od7O4GsnIcIySD9-MdYXbMMI",appKey:"e8zuU9tM3oRrN9kp9PWQwmYW"},{serverURL:"https://talkapi.dingzh.cc",lang:"zh",pageSize:1,color1:"#ff6262",color2:"#00a9c4",atEmoji:null}))};"function"==typeof Artitalk?a():getScript("https://npm.elemecdn.com/artitalk").then(a)})()}for(var elist="/artitalk/,/posts/".split(","),cpage=location.pathname,epage="/",flag=0,i=0;i<elist.length;i++)cpage.includes(elist[i])&&flag++;("all"===epage&&0==flag||epage===cpage)&&card_artitalk_injector_config()</script><script async src="https://alicdn.dingzh.cc/ding-BlogDemo/js/other/card_visual.min.js"></script><script data-pjax>function butterfly_clock_anzhiyu_injector_config(){var a=document.getElementsByClassName("sticky_layout")[0];console.log("已挂载butterfly_clock_anzhiyu"),a&&a.insertAdjacentHTML("afterbegin",'<div class="card-widget card-clock"><div class="card-glass"><div class="card-background"><div class="card-content"><div id="hexo_electric_clock"><img class="entered loading" id="card-clock-loading" src="https://alicdn.dingzh.cc/ding-BlogDemo/img/loading.gif" style="height: 120px; width: 100%;" data-ll-status="loading"/></div></div></div></div></div>')}for(var elist="/archives/,/tags/,/categories/,/anime/,/gallery/,/artitalk/,/messageboard/,/link/,/about/".split(","),cpage=location.pathname,epage="all",qweather_key="dec7b69d45ab4dc4b9c3a6e8a13eb498",gaud_map_key="92c61ec107a5fc3b3abccc79ee948148",baidu_ak_key="undefined",flag=0,clock_rectangle="119.306239,26.075302",clock_default_rectangle_enable="false",i=0;i<elist.length;i++)cpage.includes(elist[i])&&flag++;("all"===epage&&0==flag||epage===cpage)&&butterfly_clock_anzhiyu_injector_config()</script><script src="https://pv.sohu.com/cityjson?ie=utf-8"></script><script data-pjax src="https://alicdn.dingzh.cc/ding-BlogDemo/clock/clock.min.js"></script><script data-pjax>function butterfly_swiper_injector_config(){var i=document.getElementsByClassName("recent-posts")[0];console.log("已挂载butterfly_swiper"),i.insertAdjacentHTML("afterbegin",'<div class="recent-post-item" style="height: auto;width: 100%"><div class="blog-slider swiper-container-fade swiper-container-horizontal" id="swiper_container"><div class="blog-slider__wrp swiper-wrapper" style="transition-duration: 0ms;"><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/d4e383e3.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src="https://alicdn.dingzh.cc/ding-BlogDemo/img/cover/cover217.jpg" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2025-11-09</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/d4e383e3.html&quot;);" href="javascript:void(0);" alt="">对 AI Agent 的一些粗浅理解</a><div class="blog-slider__text">总结我目前 AI Agent 的一些粗浅理解</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/d4e383e3.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/b95b9d3f.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src="https://alicdn.dingzh.cc/ding-BlogDemo/img/cover/cover186.jpg" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2025-10-28</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/b95b9d3f.html&quot;);" href="javascript:void(0);" alt="">AI Trip Assistant 复盘</a><div class="blog-slider__text">USYD 5620 小组项目AI Trip Assistant 复盘</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/b95b9d3f.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/7a10715.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src="https://alicdn.dingzh.cc/ding-BlogDemo/img/cover/cover16.jpg" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2025-11-11</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/7a10715.html&quot;);" href="javascript:void(0);" alt="">什么是 MCP，什么是 MCP Server</a><div class="blog-slider__text">理解 MCP 协议及 MCP Server 的作用</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/7a10715.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/14f08eda.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src="https://alicdn.dingzh.cc/ding-BlogDemo/img/cover/cover155.jpg" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2025-11-11</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/14f08eda.html&quot;);" href="javascript:void(0);" alt="">RAG / MCP / Prompt 和一些常用的 Agent 框架</a><div class="blog-slider__text">理解 RAG、MCP 和 Prompt 在 Agent 中的角色与区别，以及常用的 Agent 框架</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/14f08eda.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/8da89045.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src="https://alicdn.dingzh.cc/ding-BlogDemo/img/cover/cover239.jpg" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2022-01-06</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/8da89045.html&quot;);" href="javascript:void(0);" alt="">seo优化超详细步骤 — hexo_butterfly</a><div class="blog-slider__text">搜索引擎收录博客详细步骤，并讲解如何对博客进行SEO优化</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/8da89045.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/b3f89ff3.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src="https://alicdn.dingzh.cc/ding-BlogDemo/img/cover/cover117.jpg" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2022-01-05</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/b3f89ff3.html&quot;);" href="javascript:void(0);" alt="">JS、CSS异步加载优化方案</a><div class="blog-slider__text">拜读Akilar店长的文章后，自己对JS、CSS异步加载的总结与体会</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/b3f89ff3.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/b4caf892.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src="https://alicdn.dingzh.cc/ding-BlogDemo/img/cover/cover131.jpg" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2022-01-07</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/b4caf892.html&quot;);" href="javascript:void(0);" alt="">部署博客中各种踩坑点记录</a><div class="blog-slider__text">部署博客也有半个月了，中间遇到了许多坑点，这里总结一下常规操作吧（其实也没多少，懒得写- -）。持续更新~</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/b4caf892.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div></div><div class="blog-slider__pagination swiper-pagination-clickable swiper-pagination-bullets"></div></div></div>')}for(var elist="undefined".split(","),cpage=location.pathname,epage="/",flag=0,i=0;i<elist.length;i++)cpage.includes(elist[i])&&flag++;("all"===epage&&0==flag||epage===cpage)&&butterfly_swiper_injector_config()</script><script defer src="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper.min.js"></script><script defer data-pjax src="https://alicdn.dingzh.cc/ding-BlogDemo/js/other/swiper_init.min.js"></script><div class="js-pjax"><script async>for(var arr=document.getElementsByClassName("recent-post-item"),i=0;i<arr.length;i++)arr[i].classList.add("wow"),arr[i].classList.add("animate__fadeIn"),arr[i].setAttribute("data-wow-duration",""),arr[i].setAttribute("data-wow-delay",""),arr[i].setAttribute("data-wow-offset",""),arr[i].setAttribute("data-wow-iteration","")</script><script async>for(var arr=document.getElementsByClassName("card-widget"),i=0;i<arr.length;i++)arr[i].classList.add("wow"),arr[i].classList.add("animate__fadeIn"),arr[i].setAttribute("data-wow-duration",""),arr[i].setAttribute("data-wow-delay",""),arr[i].setAttribute("data-wow-offset",""),arr[i].setAttribute("data-wow-iteration","")</script><script async>for(var arr=document.getElementsByClassName("article-sort-item"),i=0;i<arr.length;i++)arr[i].classList.add("wow"),arr[i].classList.add("animate__fadeIn"),arr[i].setAttribute("data-wow-duration","1.2s"),arr[i].setAttribute("data-wow-delay",""),arr[i].setAttribute("data-wow-offset",""),arr[i].setAttribute("data-wow-iteration","")</script><script async>for(var arr=document.getElementsByClassName("flink-list-card"),i=0;i<arr.length;i++)arr[i].classList.add("wow"),arr[i].classList.add("animate__backInDown"),arr[i].setAttribute("data-wow-duration","1.2s"),arr[i].setAttribute("data-wow-delay",""),arr[i].setAttribute("data-wow-offset",""),arr[i].setAttribute("data-wow-iteration","")</script></div><script defer src="https://npm.elemecdn.com/hexo-butterfly-wowjs/lib/wow.min.js"></script><script defer src="https://npm.elemecdn.com/hexo-butterfly-wowjs/lib/wow_init.js"></script></body></html>